package tech.yiyehu.modules.bss.controller;

import java.util.Arrays;
import java.util.Map;

import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import tech.yiyehu.modules.bss.entity.HabitusEntity;
import tech.yiyehu.modules.bss.service.HabitusService;
import tech.yiyehu.common.utils.PageUtils;
import tech.yiyehu.common.utils.R;



/**
 * 饮食记录
 *
 * @author yiyehu
 * @email 2681844336@qq.com
 * @date 2019-06-02 23:02:00
 */
@RestController
@Api(value="体质")
@RequestMapping("bss/habitus")
public class HabitusController {
    @Autowired
    private HabitusService habitusService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("bss:habitus:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = habitusService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("bss:habitus:info")
    public R info(@PathVariable("id") Long id){
			HabitusEntity habitus = habitusService.selectById(id);

        return R.ok().put("habitus", habitus);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("bss:habitus:save")
    public R save(@RequestBody HabitusEntity habitus){
			habitusService.insert(habitus);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @RequiresPermissions("bss:habitus:update")
    public R update(@RequestBody HabitusEntity habitus){
			habitusService.updateById(habitus);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @RequiresPermissions("bss:habitus:delete")
    public R delete(@RequestBody Long[] ids){
			habitusService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
